/*
 * @Date: 2021-09-08 15:34:58
 * @Author: Acckno1
 * @LastEditTime: 2021-09-08 16:24:25
 * @Description: 
 */
#include <iostream>
#include <cstring>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <set>
#include <bitset>
#include <utility>
using namespace std;

#define mm(a, n) memset(a, n, sizeof a)
#define mk(a, b) make_pair(a, b)

const double eps = 1e-6;
const int INF = 0x3f3f3f3f;

typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<double, double> PDD;
typedef pair<LL, LL> PLL;
typedef pair<int, LL> PIL;

inline void quickread() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
}

const int N = 50;

int n;
int l[N], r[N];
bool st[N];

unordered_map<string, int> s2i;
unordered_map<int, string> i2s;

string DFS(int u) {
    string res = "";
    if (l[u] == -1 && r[u] == -1) {
        res += i2s[u];
    } else {
        if (l[u] != -1) 
            res += "(" + DFS(l[u]);
        else
            res += "(";
    
        res += i2s[u];

        if (r[u] != -1)
            res += DFS(r[u]) + ")";
        else
            res += ")";
    }
    
    return res;
}

inline void solution() {

    cin >> n;

    for (int i = 1; i <= n; i ++ ) {
        string a;
        int lc, rc;
        cin >> a >> lc >> rc;
        s2i[a] = i;
        i2s[i] = a;
        l[i] = lc, r[i] = rc;
        st[lc] = st[rc] = true;
    }

    int root;
    for (int i = 1; i <= n; i ++ )
        if (!st[i]) 
            root = i;
    
    string s = DFS(root);
    if (s.size() > 2) {
        s = s.substr(1);
        s.pop_back();
    }
    cout << s << endl;
}

int main() {
    freopen("input.txt", "r", stdin);
    quickread();
    solution();
    return 0;
}